package com.itheima.sms;

import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.aliyun.teaopenapi.models.Config;

//手机端交互的工程

public class Sample {

    /**
     * 使用AK&SK初始化账号Client
     * @param accessKeyId
     * @param accessKeySecret
     * @return Client
     * @throws Exception
     */
    public static com.aliyun.dysmsapi20170525.Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
        //创建配置对象
        Config config = new Config()

                // 您的AccessKey ID 访问密钥的id
                .setAccessKeyId(accessKeyId)
                // 您的AccessKey Secret 链接密钥
                .setAccessKeySecret(accessKeySecret);
        // 访问的域名
        config.endpoint = "dysmsapi.aliyuncs.com";
        //返回新创建的域名对象
        return new com.aliyun.dysmsapi20170525.Client(config);
    }

    public static void main(String[] args_) throws Exception {
        java.util.List<String> args = java.util.Arrays.asList(args_);
        com.aliyun.dysmsapi20170525.Client client = Sample.createClient("accessKeyId", "accessKeySecret");
        //发送短信消息请求 对象
        SendSmsRequest sendSmsRequest = new SendSmsRequest()
                //写入短信签名名称
                .setSignName("阿里云短信测试")
                //短信模板ID
                .setTemplateCode("SMS_154950909")
                //接收短信的手机号
                .setPhoneNumbers("15373149603")
                //短信模板变量对应的实际值 验证码
                .setTemplateParam("{\"code\":\"1234\"}");
        // 复制代码运行请自行打印 API 的返回值  发送短信
        client.sendSms(sendSmsRequest);
    }
}
